package com.invite.me.beans.presenter;

import android.util.Log;

import com.google.gson.Gson;
import com.invite.me.api.UrlConstants;
import com.invite.me.beans.fabean.BlindDataParticularsFaBean;
import com.invite.me.beans.fabean.BlindDataPartiicularsFaBean;
import com.invite.me.beans.fabean.HomeFaGrdllistBean;
import com.invite.me.beans.res.InformationxxShouBean;
import com.invite.me.ui.home.HomeActivity;
import com.invite.me.ui.yaoyue.BlindDataParticularsActivity;
import com.invite.me.util.SspPrefUtils;
import com.invite.me.wlqq.Constants;
import com.invite.me.wlqq.Contract;
import com.invite.me.wlqq.RxJavaDataImpl;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

public class BlindDataParticularsPresenter implements Contract.BasePresenter{
    BlindDataParticularsActivity homeActivity;

    public BlindDataParticularsPresenter(BlindDataParticularsActivity signInActivity) {
        this.homeActivity = signInActivity;
        homeActivity.setPresenter(this);
    }

    @Override
    public void start() {

    }
    // 查询详情
    public void loadHomeData(String id) {

//        HashMap<String, Object> hashMap = new HashMap<>();
//        hashMap.put(Constants.HEADER_KEY, Constants.HEADER_VALUE);
//        hashMap.put("userId", SspPrefUtils.getString(Constants.SSPTOKEN, ""));
//        BlindDataPartiicularsFaBean homeFaGrdllistBean =new BlindDataPartiicularsFaBean();
//        homeFaGrdllistBean.setUserId(id);
//
//
//        Gson gson = new Gson();
//        String phoneNumber = gson.toJson(homeFaGrdllistBean);
//        RequestBody requestBody = RxJavaDataImpl.getRequestBody(phoneNumber);
        Map<String, Object> headrMap = new HashMap<>();
        headrMap.put("Content-Type", "application/json");
        headrMap.put("userId", SspPrefUtils.getString(Constants.SSPTOKEN, ""));

        HashMap<String,Object> map=new HashMap<>();
        map.put("userId",id);

        RxJavaDataImpl.getData(UrlConstants.API_HQYHXX, headrMap, map, new Observer() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(Object value) {
                if (value instanceof ResponseBody) {
                    try {
                        ResponseBody responseBody = (ResponseBody) value;
                        String str = responseBody.string();
                        Gson gson = new Gson();
                        BlindDataPartiicularsFaBean gankInfo = gson.fromJson(str, BlindDataPartiicularsFaBean.class);

                        homeActivity.onDataSucess(gankInfo);


                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onError(Throwable e) {
                Log.e("onerror", e + "");
                homeActivity.onDataFaile(e);
            }

            @Override
            public void onComplete() {
                homeActivity.onComplete();
            }
        });
    }

    // 发起邀约
   // public void faqiyaoyue(String address,String city,String quyu,int liexing,String weidu,String jingdu,String sheng,String yonghua,String yonghub,String zhi) {
        public void faqiyaoyue(String address,String city,String quyu,String liexing,Double weidu,Double jingdu,String sheng,String yonghua,String yonghub,Double zhi) {

        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put(Constants.HEADER_KEY, Constants.HEADER_VALUE);
        hashMap.put("userId", SspPrefUtils.getString(Constants.SSPTOKEN, ""));
            BlindDataParticularsFaBean homeFaGrdllistBean =new BlindDataParticularsFaBean();
        homeFaGrdllistBean.setAddress(address);
        homeFaGrdllistBean.setCity(city);
        homeFaGrdllistBean.setDistrict(quyu);
        homeFaGrdllistBean.setLocationType(liexing);
        homeFaGrdllistBean.setPosx(weidu);
        homeFaGrdllistBean.setPosy(jingdu);
        homeFaGrdllistBean.setProvince(sheng);
        homeFaGrdllistBean.setUserIda(yonghua);
        homeFaGrdllistBean.setUserIdb(yonghub);
        homeFaGrdllistBean.setValue(zhi);

        Gson gson = new Gson();
        String phoneNumber = gson.toJson(homeFaGrdllistBean);
        RequestBody requestBody = RxJavaDataImpl.getRequestBody(phoneNumber);

        RxJavaDataImpl.postData(UrlConstants.GAQIYAOYUE, hashMap, requestBody, new Observer() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(Object value) {
                if (value instanceof ResponseBody) {
                    try {
                        ResponseBody responseBody = (ResponseBody) value;
                        String str = responseBody.string();
                        Gson gson = new Gson();



                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onError(Throwable e) {
                Log.e("onerror", e + "");
                homeActivity.onDataFaile(e);
            }

            @Override
            public void onComplete() {
                homeActivity.onComplete();
            }
        });
    }

}
